package com.study.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 商品类别
 */
@Getter
@AllArgsConstructor
public enum GoodsGategory {

    ELECTRIC_APP("10001","电器"),
    FURNITURE("10002","家具"),
    COSTUME("10003","服饰"),
    MA_INFANT("10004","母婴"),
    FOOD("10005","食品"),
    BOOK("10006","图书"),
    ;

    //商品类别编码
    private final String code;

    //商品类别描述
    private final String description;

    public static GoodsGategory of(String code) {

        Objects.requireNonNull(code);

        return Stream.of(values())
                .filter(bean -> bean.equals(code))
                .findAny()
                .orElseThrow(
                        () -> new IllegalArgumentException(code + "不存在！")
                );
    }
}
